load("@rules_jvm_external//:defs.bzl", "artifact")
load("//:common_defs.bzl", "minSdkVersion", "targetSdkVersion")

licenses(["notice"])  # Apache 2.0

android_library(
    name = "IdlingResourceSampleLib",
    srcs = glob(["app/src/main/**/*.java"]),
    custom_package = "com.example.android.testing.espresso.IdlingResourceSample",
    manifest = "app/src/main/AndroidManifest.xml",
    resource_files = glob(["app/src/main/res/**/*"]),
    deps = [
        artifact("androidx.annotation:annotation"),
        artifact("androidx.test.espresso:espresso-idling-resource"),
        artifact("com.google.guava:guava"),
    ],
)

android_binary(
    name = "IdlingResourceSample",
    custom_package = "com.example.android.testing.espresso.IdlingResourceSample",
    manifest = "app/src/main/AppManifest.xml",
    manifest_values = {
        "minSdkVersion": minSdkVersion,
        "targetSdkVersion": targetSdkVersion,
    },
    deps = [":IdlingResourceSampleLib"],
)

android_library(
    name = "IdlingResourceSampleTestLib",
    srcs = glob(["app/src/androidTest/**/*.java"]),
    custom_package = "com.example.android.testing.espresso.IdlingResourceSample.test",
    deps = [
        artifact("androidx.test.espresso:espresso_idling_resource"),
        ":IdlingResourceSampleLib",
        "//:test_deps",
    ],
)

android_binary(
    name = "IdlingResourceSampleTest",
    custom_package = "com.example.android.testing.espresso.IdlingResourceSample.test",
    instruments = ":IdlingResourceSample",
    manifest = "app/src/androidTest/AndroidManifest.xml",
    manifest_values = {
        "minSdkVersion": minSdkVersion,
        "targetSdkVersion": targetSdkVersion,
    },
    deps = [":IdlingResourceSampleTestLib"],
)

API_LEVELS = [
    "19_x86",
    "21_x86",
    "22_x86",
    "23_x86",
]

[android_instrumentation_test(
    name = "IdlingResourceSampleInstrumentationTest_%s" % API_LEVEL,
    target_device = "@android_test_support//tools/android/emulated_devices/generic_phone:android_%s_qemu2" % API_LEVEL,
    test_app = ":IdlingResourceSampleTest",
) for API_LEVEL in API_LEVELS]
